<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>登入</title>
  <meta name="renderer" content="webkit">
  <meta name="_csrf" content="${_csrf.token}"/>
  <meta name="_csrf_header" content="${_csrf.headerName}"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="icon" href="/images/logo.png">
  <link rel="stylesheet" href="/css/admin.css">
  <link rel="stylesheet" href="/js/layui/css/layui.css">
  <link rel="stylesheet" href="/css/login.css">
  <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
  <style>
    .layui-icon-login-qq {
      color: blue;
    }
  </style>
</head>
<body>
<script>
  var token = $("meta[name='_csrf']").attr("content");
  var header = $("meta[name='_csrf_header']").attr("content");
  $.ajaxSetup({ //发送请求前触发
    beforeSend: function (xhr) { //可以设置自定义标头
      xhr.setRequestHeader(header, token);
    }
  })
</script>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

  <div class="layadmin-user-login-main">
    <div class="layadmin-user-login-box layadmin-user-login-header">
      <h2 style="color: #fff!important;">CG Admin</h2>
    </div>
    <form class="layadmin-user-login-box layadmin-user-login-body layui-form">
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
        <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
               class="layui-input">
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
        <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码"
               class="layui-input">
      </div>
      <div class="layui-form-item">
        <div class="layui-row">
          <div class="layui-col-xs7">
            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
            <input type="text" name="verificationCode" lay-verify="required" placeholder="图形验证码"
                   class="layui-input">
          </div>
          <div class="layui-col-xs5">
            <div style="margin-left: 10px;">
              <img src="/verifycode/get" class="layadmin-user-login-codeimg"
                   id="codeImg" alt="验证码" />
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item" style="margin-bottom: 20px;">
        <input type="checkbox" name="remember-me" lay-skin="primary" title="记住我">
        <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
          <span>记住我</span>
          <i class="layui-icon layui-icon-ok"></i>
        </div>
        <a href="/forget" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>
      </div>
      <div class="layui-form-item">
        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登 入</button>
      </div>
      <div class="layui-trans layui-form-item layadmin-user-login-other cc_cursor">
        <label>社交账号登入</label>
        <a href="/binding/qq"><i class="layui-icon layui-icon-login-qq"></i></a>
<#--        <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>-->
<#--        <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>-->
      </div>
    </form>
  </div>

  <div class="layui-trans layadmin-user-login-footer">
    <p>© 2020 <a href="javascript:;" target="_blank">成员管理系统</a></p>
  </div>

</div>

<script src="/js/layui/layui.js"></script>
<script type="text/javascript">

  layui.use(['form', 'layer'], function () {
    var form = layui.form
            , $ = layui.$
            , layer = layui.layer;
    setBackGround();
    form.render();

    form.on('submit(login)', function (obj) {
      console.log(obj.field)
      $.post('/login', obj.field, function (res) {
        if (res.success) {
          layer.msg('登录成功！', {icon: 6, time: 1200});
          location.href = '/admin/index';
        } else {
          layer.msg(res.msg, {icon: 5});
          $('input[name=code]').val('');
          $('#codeImg').attr('src', '/verifycode/get?date='+ new Date().getTime());
        }
      })
      return false;
    });


    $('#codeImg').click(function(){
      this.src = '/verifycode/get?date='+ new Date().getTime();
    }).click().show();

  });

  function setBackGround() {
    document.body.style.backgroundImage= "url(https://bing.biturl.top/?resolution=1920&format=image&index=0&mkt=zh-CN)";
  }
</script>
</body>
</html>